#!/usr/bin/env python
# coding=utf-8
# __author__ = 'Yunchao Ling'

from Bio import SeqIO
from Bio.Alphabet import IUPAC

IUPAC.unambiguous_dna
for seq_record in SeqIO.parse("/home/sleepyhead/Downloads/sequence.fasta", "fasta"):
    # print(seq_record.id)
    # print(repr(seq_record.seq))
    # print(len(seq_record))
    # 不论序列是否反向，格式化序列时前面不变后面+1
    seq_record.seq=seq_record.seq[348:1191]
    # 前面后面都+1，如果序列反向倒过来数字顺序
    new_record=seq_record.reverse_complement(id=seq_record.id+":c1191-349",description=seq_record.description[seq_record.description.find(" ")+1:])
    print(new_record.seq[-5:])
    print(new_record.id)
    print(new_record.description)

    SeqIO.write(new_record, "/home/sleepyhead/my_example.faa", "fasta")